<?php

namespace App\Http\Controllers\Chanjet;

use App\Http\Controllers\Controller;
use Darabonba\GatewaySpi\Models\InterceptorContext\response;
use Illuminate\Http\Request;

class TplusInventoryInfo extends BaseController
{
    public function getExternalData(){
        $common = new TplusCommonController();
        $res = $common->getExternalData("TplusInventoryInfo",$this->mangerinfo['org_id']);
        return $res;
    }
    public function getlist(Request $request)
    {
        $memberinfo = $this->mangerinfo;
        $isgetall = $request->isgetall ?? 0;

        $start_time = $this->getTplusFormatDate($request->start_time);
        $end_time = $this->getTplusFormatDate($request->end_time);
        if(!$start_time || !$end_time) {
            return response()->json(['code'=>'001','msg'=>'查询条件不能为空']);
        }
        $dic = [];
        //期间 范围
        //日期格式转化
//        $start_time = date('Y.m',strtotime($start_time));
//        $end_time = date('Y.m',strtotime($end_time));
//        $dic[] = ['Period',$start_time,$end_time];
        $dic[] = ['VoucherDate',$start_time,$end_time];
        $dic[] = ['cpid',$memberinfo['cpid']];
        $checkData = [
            'controllerName'=>'TplusInventoryInfo',
            'org_id'=>$this->mangerinfo['org_id'],
            'condition'=>$dic
        ];
        $reportDataCheck = $this->checkReportCache($checkData);
        if($reportDataCheck['code'] != '000'){
            return response()->json(['code'=>'001','msg'=>'T+数据请求失败,请检查']);
        }

        if($reportDataCheck['data']){
            $request->cache_ids = $reportDataCheck['data'];
        }else{
            $request->cache_ids = [];
        }
        $list = \App\Models\Chanjet\TplusInventoryInfo::getList($request, $memberinfo, $isgetall);
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
